'use strict';

const Service = require('egg').Service;
const axios = require('axios').default;

class GithubService extends Service {
  async getFollowers({ page = 1, limit = 10 }) {
    const { ctx } = this;
    const res = await axios.get(`https://api.github.com/users/tj/followers?page=${page}&per_page=${limit}`);
    if (res.status === 200) {
      ctx.status = 200;
      return {
        code: 0,
        data: {
          list: res.data,
          page,
          limit,
        },
        message: 'ok',
      };
    }
    ctx.status = 500;
    return {
      code: 1,
      data: { list: [], page, limit },
      message: '查询出错',
    };
  }
}

module.exports = GithubService;
